<template>
  <view class="whe_maxv_view pad_15 boxs">
    <view>
      <view class="disp centerdq" style="width: 5px;height: 20px;background-color: #3a9e5f;border-radius: 5px;margin-right: 10px"></view>
      <text class="centerdq fz_18 em">{{ data.name }}</text>
    </view>
    <!--      推荐商品列表-->
    <view class="wh_f mag_t-15">
      <view class="flex_1">
        <view @click="addDetail(item)" v-for="(item,index) in list" :key="index">
          <view v-if="index % 2 == 0"
                class="ba_white xyy bor_10" style="margin-bottom: 10px">
            <view class="img_zfx" style="width:100%">
              <view>
                <image :src="item?.image[0]" alt=""/>
              </view>
            </view>
            <view class="pad_5_10 boxs fz_12">
              <view class="fz_16 em ccsl_2">
                {{ item?.name }}
              </view>
              <view class="wz_huang" style="padding: 4px">{{ item.sales }}人买过</view>
              <view style="padding-bottom: 2px">
                <text class="scx wz_hui fz_12 centerdq mag_l-5"> ¥ {{item.re_price}}</text>
              </view>
              <view class="wh_f pad_b-10">
                <view class="flex_1 wz_red">
                  <text class="">¥</text>
                  <text class="fz_16 em">{{ parseInt(item.price) }}</text>
                  <text class="fz_10 em ">.{{ String(item.price).split('.')[1] }}</text>
                  <!--                      <text class=" fz_10 mag_l-5">折后价</text>-->
                </view>
                <view>
                  <img @click.stop="addShop(item)" class="centerdq" src="../../static/img/tianjia.png"
                       style="width: 20px;height: 20px" alt="">
                </view>
              </view>


              <view v-if="false" class="split_3">
                <view class=" wz_rigdq">
                  <image v-if="item.cart_amount>0" @click.stop="addShopList(false,item,index,$event)"
                         class="centerdq" src="../../static/img/jianshao.png"
                         style="width: 20px;height: 20px"/>
                </view>
                <view class="wz_jz centerdq">
                  <text v-if="item.cart_amount>0" class="centerdq">{{ item.cart_amount }}</text>
                </view>
                <view>
                  <image @click.stop="addShopList(true,item,index)" class="centerdq"
                         src="../../static/img/tianjia.png"
                         style="width: 18px;height: 18px"/>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
      <view style="width: 10px"></view>
      <view class="flex_1">
        <view @click="addDetail(item)" v-for="(item,index) in list" :key="index">
          <view v-if="index % 2 == 1"
                class="ba_white xyy bor_10" style="margin-bottom: 10px">
            <view class="img_zfx" style="width:100%">
              <view>
                <image :src="item?.image[0]" alt=""/>
              </view>
            </view>
            <view class="pad_5_10 boxs fz_12">
              <view class="fz_16 em ccsl_2">
                {{ item?.name }}
              </view>
              <view class="wz_huang" style="padding: 4px">{{ item.sales }}人买过</view>
              <view style="padding-bottom: 2px">
                <text class="scx wz_hui fz_12 centerdq mag_l-5"> ¥ {{item.re_price}}</text>
              </view>
              <view class="wh_f pad_b-10">
                <view class="flex_1 wz_red">
                  <text class="">¥</text>
                  <text class="fz_16 em">{{ parseInt(item.price) }}</text>
                  <text class="fz_10 em ">.{{ String(item.price).split('.')[1] }}</text>
                  <!--                      <text class=" fz_10 mag_l-5">折后价</text>-->
                </view>
                <view>
                  <img @click.stop="addShop(item)" class="centerdq" src="../../static/img/tianjia.png"
                       style="width: 20px;height: 20px" alt="">
                </view>
              </view>


              <view v-if="false" class="split_3">
                <view class=" wz_rigdq">
                  <image v-if="item.cart_amount>0" @click.stop="addShopList(false,item,index,$event)"
                         class="centerdq" src="../../static/img/jianshao.png"
                         style="width: 20px;height: 20px"/>
                </view>
                <view class="wz_jz centerdq">
                  <text v-if="item.cart_amount>0" class="centerdq">{{ item.cart_amount }}</text>
                </view>
                <view>
                  <image @click.stop="addShopList(true,item,index)" class="centerdq"
                         src="../../static/img/tianjia.png"
                         style="width: 18px;height: 18px"/>
                </view>
              </view>
            </view>
          </view>
        </view>
      </view>
    </view>
    <view v-if="list.length<1" class="jz_flex" style="height: 60%">
      <view class="wz_jz">
        <image style="width: 200px;height: 130px" src="https://xdjzapi.towngo.cn/uploads/images/wx/202507/08/xcx_1751945016_KEXbwbZngN.png"></image>
        <view class="mag_t-20">暂无活动商品!</view>
      </view>
    </view>

    <up-popup
        :mask-closable="true"
        @close="close"
        @open="open"
        customStyle="border-radius: 20px 20px 0 0"
        :show="show"
        mode="bottom">
      <view>
        <view class="wh_f_r" style="background-color: #f5f5f5;border-radius: 20px 20px 0 0;padding:20px">
          <view style="width: 100px;">
            <view class="img_zfx">
              <img :src="additem?.image[0]"/>
            </view>
          </view>
          <view class="pad_l-20">
            <view class="wh_f_l">
              <view>{{ additem.name }}</view>
              <view>
                <up-icon @click="close" name="close" color="#383838" size="20"></up-icon>
              </view>
            </view>
            <view class="pad_10_0 fz_12">{{ additem.category_pstr }}</view>
            <view>
              <text class="wz_red ">¥{{ additem.discount }}</text>
              <text class="fz_12"> / {{ additem.specs }}</text>
            </view>
          </view>
        </view>
        <view style="padding: 20px">
          <view class="wh_f_l">
            <view class="fz_14">购买数量</view>
            <view>
              <up-number-box class="centerdq" button-size="26" buttonWidth="26"
                             @change="valChange($event,additem)"
                             v-model="additem.amount"
                             :min="1"></up-number-box>
            </view>
          </view>
          <view style="padding-top: 20px">
            <view @click="addShoppingCars" class="bor_25 pad_10 wz_jz fz_14 wz_white" style="background-color:#3a9e5f">加入购物车</view>
          </view>
        </view>

      </view>
    </up-popup>
    <up-toast ref="uToastRef"></up-toast>
  </view>
</template>
<script>
import {addCartAmount, addShoppingCart, delCart, getactivityShopList, getShopGoodsList} from "../../Api/shop";

export default {
  name: "index",
  data(){
    return{
      textValue:'',
      list:[],
      data:{},
      show:false,
      additem:{
        image:[]
      }
    }
  },
  onLoad(options){
    let item = JSON.parse(options.data)
    this.data = item
    this.getList(item.id)
  },
  onShow(){
  },
  methods:{
    close(){
      this.show = false
    },
    //确认添加购物车
    addShoppingCars(){
      addShoppingCart({
        goods_id:this.additem.id,
        amount:this.additem.amount
      }).then(res=>{
        if(res.success){
          this.showToast('加购成功!')
          this.show = false
        }else{
          this.show = false
        }
      })
    },
    // 添加/删除购物车商品
    valChange(e){
      this.additem.amount = e.value
    },
    //添加购物车
    addShop(e){
      this.additem = e
      this.additem.amount = 1
      this.show = true
      // addShoppingCart({
      //   goods_id:e.id
      // }).then(res=>{
      //   this.showToast('添加购物车成功!')
      // }).catch(err=>{
      //   this.showToast('添加购物车失败!')
      // })
    },
    //消息提示
    showToast(msg, type = "default") {
      uni.showToast({
        title: msg,
        icon: "none", // 图标类型，可选值：success, none
        duration: 2000 // 显示时间，单位毫秒
      });
    },
    addDetail(e){
      const params = { id:e.id}; // 待传递的参数
      uni.navigateTo({
        url: `/shophome/shopDetail/index?id=${params.id}`
      });
    },

    getList(e){
      getactivityShopList({
        act_id:e
      }).then(res=>{
        console.log('活动商品列表',res.data)
        this.list = res.data.data
      })
    },
    getAddress(){

    }
  }
}
</script>
<style scoped lang="scss">

</style>
